<div id="gallery" class="clear">
    <div id="gallery-inner">
        <?php for ($i = 1; $i <= 5; $i++): ?>
            <?php $picture = sprintf("pic%s", $i); ?>
            <div class="item-wrapper">
                <div id="<?php echo $picture; ?>-item" class="item">
                    <?php if($user->profile->$picture == null): ?>
                        <?php echo CHtml::image(ImageUtil::createImagePath($user->profile->$picture)); ?>
                    <?php endif; ?>
                </div>
                <?php echo CHtml::hiddenField($picture, $user->profile->$picture); ?>
                <div class="control">
                    <?php if ($user->scenario == 'register' || $user->id === ShortUtil::user()->id): ?>
                        <?php echo CHtml::button(TranslateUtil::t('Delete', array(), TranslateUtil::CATEGORY_BUTTON), array(
                            'class' => 'button',
                            'onClick' => '
                                $("#' . $picture . '-item").html("' . TranslateUtil::t('Click on box to upload picture of yourself') . '");
                                $("#' . $picture . '").val(null);
                            ',
                        )); ?>
                    <?php endif; ?>
                </div>
            </div>
            <?php $script .= '
                $("#' . $picture . '-item").upload({
                    name: "Filedata",
                    action: "' . ShortUtil::homeUrl() . 'site/upload",
                    enctype: "multipart/form-data",
                    autoSubmit: true,
                    onComplete: function(response) {
                        $("#' . $picture . '-item").html("<img src=\"' . ShortUtil::homeUrl() . ImageUtil::SMALL_PATH . '" + response + "\" />");
                        $("#' . $picture . '").val(response);
                    },
                });
            '; ?>
        <?php endfor; ?>
    </div>
</div>

<?php ShortUtil::registerScriptFile(ShortUtil::themePath() . '/js/jquery.ocupload-1.1.2.js', CClientScript::POS_HEAD); ?>
<?php ShortUtil::clientScript()->registerScript('upload', $script); ?>